package com.doyens.gmall.product.controller;

import com.doyens.gmall.common.result.Result;
import com.doyens.gmall.common.result.ResultCodeEnum;
import com.doyens.gmall.model.product.BaseAttrInfo;
import com.doyens.gmall.model.product.BaseCategory1;
import com.doyens.gmall.model.product.BaseCategory2;
import com.doyens.gmall.model.product.BaseCategory3;
import com.doyens.gmall.product.service.ManageService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/product")
@Api(tags = "商品基础属性接口")
public class BaseManageController {

    @Autowired
    private ManageService manageService;

    @GetMapping("getCategory1")
    public Result getCategory1(){
        List<BaseCategory1> category1list = manageService.getCategory1();

//        Result<Object> result1 = new Result<>();
//        result1.setCode(ResultCodeEnum.SUCCESS.getCode());
//        result1.setMessage(ResultCodeEnum.SUCCESS.getMessage());
//        result1.setData(category1list);

        Result<List<BaseCategory1>> result = Result.ok(category1list);
        return  result;
    }

    @GetMapping("getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable("category1Id") Long category1Id){
       List<BaseCategory2> category2List =  manageService.getCategory2(category1Id);
       return Result.ok(category2List);
    }

    @GetMapping("getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable("category2Id") Long category2Id){
        List<BaseCategory3> baseCategory3List = manageService.getCategory3(category2Id);
        return Result.ok(baseCategory3List);

    }

    //attInfoList/0/0/61
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@PathVariable("category1Id") Long category1Id,
                               @PathVariable("category2Id") Long category2Id,
                               @PathVariable("category3Id") Long category3Id){
            List<BaseAttrInfo> baseAttrInfos = manageService.getAttrInfoList(category1Id,category2Id,category3Id);
            return Result.ok(baseAttrInfos);

    }

    @PostMapping("saveAttrInfo")
    /**
     * 添加或者修改平台属性
     */
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        manageService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }
}
